// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/functions/registerer.h>
#include <pollux/functions/lib/registration_helpers.h>
#include <pollux/functions/prestosql/arithmetic.h>
#include <pollux/functions/prestosql/decimal_functions.h>

namespace kumo::pollux::functions {
    namespace {
        void registerMathOperators(const std::string &prefix = "") {
            registerBinaryFloatingPoint<PlusFunction>({prefix + "plus"});
            register_function<
                PlusFunction,
                IntervalDayTime,
                IntervalDayTime,
                IntervalDayTime>({prefix + "plus"});
            registerBinaryFloatingPoint<MinusFunction>({prefix + "minus"});
            register_function<
                MinusFunction,
                IntervalDayTime,
                IntervalDayTime,
                IntervalDayTime>({prefix + "minus"});
            registerBinaryFloatingPoint<MultiplyFunction>({prefix + "multiply"});
            register_function<MultiplyFunction, IntervalDayTime, IntervalDayTime, int64_t>(
                {prefix + "multiply"});
            register_function<MultiplyFunction, IntervalDayTime, int64_t, IntervalDayTime>(
                {prefix + "multiply"});
            register_function<
                IntervalMultiplyFunction,
                IntervalDayTime,
                IntervalDayTime,
                double>({prefix + "multiply"});
            register_function<
                IntervalMultiplyFunction,
                IntervalDayTime,
                double,
                IntervalDayTime>({prefix + "multiply"});
            registerBinaryFloatingPoint<DivideFunction>({prefix + "divide"});
            register_function<
                IntervalDivideFunction,
                IntervalDayTime,
                IntervalDayTime,
                double>({prefix + "divide"});
            registerBinaryFloatingPoint<ModulusFunction>({prefix + "mod"});
        }
    } // namespace

    void registerMathematicalOperators(const std::string &prefix = "") {
        registerMathOperators(prefix);

        registerDecimalPlus(prefix);
        registerDecimalMinus(prefix);
        registerDecimalMultiply(prefix);
        registerDecimalDivide(prefix);
        registerDecimalModulus(prefix);
    }
} // namespace kumo::pollux::functions
